/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tabelmodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Menu;

/**
 *
 * @author tashiba
 */
public class MenuTableModel extends AbstractTableModel {

    private List<Menu> men = new ArrayList<Menu>();

    public MenuTableModel(List<Menu> menu) {
        this.men = menu;
    }

    public void deleteMenu(int row) {
        men.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updateMenu(int row, Menu menu) {
        men.set(row, menu);
        fireTableRowsUpdated(row, row);
    }

    public void addMenu(Menu menu) {
        men.add(menu);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    @Override
    public int getRowCount() {
        return men.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Menu b = men.get(rowIndex);
        switch (columnIndex) {
             case 0:
                return b.getIdMenu();
            case 1:
                return b.getNamaMenu();
            case 2:
                return b.getKategori().getIdKategori() + " " + b.getKategori().getNamaKategori();
            case 3:
                return b.getHargaMenu();

            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
             case 0:
                return "Id Menu";
            case 1:
                return "Nama Menu";
            case 2:
                return "Kategori";
            case 3:
                return "Harga Menu";
            default:
                return "";
        }
    }
}

